package com.yunji.framework_template.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yunji.framework_template.biz.service.NewsCrawledService;
import com.yunji.framework_template.common.web.Page;
import com.yunji.framework_template.common.web.Result;
import com.yunji.framework_template.orm.persistence.model.NewsCrawled;

/**
 * Created by fenglibin on 2018/11/28.
 */
@Controller
@RequestMapping("/newsCrawled/")
public class NewsCrawledController {

    @Autowired
    NewsCrawledService newsCrawledService;

    @RequestMapping("selectAll")
    @ResponseBody
    public Result<List<NewsCrawled>> selectAll() {
        return Result.success(newsCrawledService.selectAll());
    }

    @RequestMapping("select")
    @ResponseBody
    public Result<NewsCrawled> selectByPrimaryKey(String urlMd5) {
        return Result.success(newsCrawledService.selectByPrimaryKey(urlMd5));
    }

    @RequestMapping("selectByCondition1")
    @ResponseBody
    public Result<List<NewsCrawled>> selectByCondition(NewsCrawled record) {
        return Result.success(newsCrawledService.selectByCondition(record));
    }

    @RequestMapping("count")
    @ResponseBody
    public Result<Long> count(NewsCrawled record) {
        return Result.success(newsCrawledService.count(record));
    }

    @RequestMapping("insert")
    @ResponseBody
    public Result<Integer> insertSelective(NewsCrawled record) {
        return Result.success(newsCrawledService.insertSelective(record));
    }

    @RequestMapping("update")
    @ResponseBody
    public Result<Integer> updateByPrimaryKeySelective(NewsCrawled record) {
        return Result.success(newsCrawledService.updateByPrimaryKeySelective(record));
    }

    @RequestMapping("selectByPage")
    @ResponseBody
    public Result<Page<List<NewsCrawled>>> selectByPage(Page<NewsCrawled> page) {
        List<NewsCrawled> list = null;
        page = page.sequentialDisplayCalculate(newsCrawledService.count(page.getObj()));
        if (page.getTotalCount() > 0) {
            list = newsCrawledService.selectByPage(page);
        }
        Page<List<NewsCrawled>> result = new Page<List<NewsCrawled>>(page, list);
        return Result.success(result);
    }

    @RequestMapping("deleteByCondition")
    @ResponseBody
    public Result<Integer> deleteByCondition(NewsCrawled record) {
        return Result.success(newsCrawledService.deleteByCondition(record));
    }

    @RequestMapping("delete1")
    @ResponseBody
    public Result<Integer> deleteByPrimaryKey(String urlMd5) {
        return Result.success(newsCrawledService.deleteByPrimaryKey(urlMd5));
    }

}
